<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018-12-27
  Time: 下午 3:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.4.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.4.5/layui/css/layui.css" media="all">
</head>
<body>
<div class="x-nav" style="border-bottom: 0;">
    <a class="layui-btn layui-btn-radius"  href="javascript:location.replace(location.href);" title="刷新">
        刷&nbsp;&nbsp;&nbsp;&nbsp;新</a>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>系统参数设置</legend>
</fieldset>

<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">会员推荐参数设置</li>
        <li>商城购物返佣参数设置</li>
    </ul>
    <div>
        <text style="color: red">注意：所有的比例设置，参数值为整数。例如，要设置为30%，在比例输入处请填写30</text>
    </div>
    <div class="layui-tab-content">

            <div class="layui-tab-item layui-show">
                <form class="layui-form" action="" lay-filter="save1" id="save1">
                <div class="layui-form-item">
                    <label class="layui-form-label">成为VIP金额</label>
                    <div class="layui-input-block">
                        <input type="text" name="vipMemberMoney" lay-verify="title"
                               value="${systemConfig.vipMemberMoney}" lay-verify="required|number"
                               autocomplete="off" placeholder="成为VIP金额" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">一级推荐奖比例</label>
                    <div class="layui-input-block">
                        <input type="text" name="vipMemberOneMoney"
                               value="${systemConfig.vipMemberOneMoney}" lay-verify="required|number"
                               lay-verify="title" autocomplete="off" placeholder="一级推荐奖比例" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">二级推荐奖比例</label>
                    <div class="layui-input-block">
                        <input type="text" name="vipMemberTwoMoney"
                               value="${systemConfig.vipMemberTwoMoney}" lay-verify="required|number"
                               lay-verify="title" autocomplete="off" placeholder="二级推荐奖比例" class="layui-input">
                    </div>
                </div>

                <button class="layui-btn layui-btn-radius" lay-submit lay-filter="save1">保存会员推荐参数</button>
                </form>
            </div>


        <%--商城消费返佣设置--%>

            <div class="layui-tab-item">
                <form class="layui-form" action="" lay-filter="save2" id="save2">
                <div class="layui-form-item">
                    <label class="layui-form-label">最低消费</label>
                    <div class="layui-input-block">
                        <input type="text" name="minimumMoney"
                               value="${systemConfig.minimumMoney}" lay-verify="required|number"
                               lay-verify="title" autocomplete="off" placeholder="最低消费" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">一级返佣比例</label>
                    <div class="layui-input-block">
                        <input type="text" name="oneMoney"
                               value="${systemConfig.oneMoney}" lay-verify="required|number"
                               lay-verify="title" autocomplete="off" placeholder="一级返佣比例" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">二级返佣比例</label>
                    <div class="layui-input-block">
                        <input type="text" name="twoMoney"
                               value="${systemConfig.twoMoney}" lay-verify="required|number"
                               lay-verify="title" autocomplete="off" placeholder="二级推荐奖比例" class="layui-input">
                    </div>
                </div>

                <button class="layui-btn layui-btn-warm layui-btn-radius" lay-submit  lay-filter="save2" >保存商城消费返佣参数</button>
                </form>
            </div>

    </div>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate','element'], function(){
        var $ = layui.jquery
            ,element = layui.element,//Tab的切换功能，切换事件监听等，需要依赖element模块
        form = layui.form;

        //保存会员推荐参数
        form.on('submit(save1)', function(data){
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // });

            $.ajax({
                url:'/adminSystem/saveSystemConfig',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    vipMemberMoney:data.field.vipMemberMoney,
                    vipMemberOneMoney:data.field.vipMemberOneMoney,
                    vipMemberTwoMoney:data.field.vipMemberTwoMoney
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                    console.log('发送前')*/
                },
                success:function(dataA){
                    layer.alert(dataA.msg, {
                        title: '保存结果'
                    });
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });

            return false;
        });
        //保存商城购物返佣参数
        form.on('submit(save2)', function(data){
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })

            $.ajax({
                url:'/adminSystem/saveSystemConfig',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    minimumMoney:data.field.minimumMoney,
                    oneMoney:data.field.oneMoney,
                    twoMoney:data.field.twoMoney
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                    console.log('发送前')*/
                },
                success:function(dataA){
                    layer.alert(dataA.msg, {
                        title: '保存结果'
                    });
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });



            return false;
        });
    });
</script>


</body>
</html>
